package flockingGA;

import jenes.chromosome.DoubleChromosome;
import jenes.population.Fitness;
import jenes.population.Individual;

public class FitnessDoubleChromosomeSync extends Fitness<DoubleChromosome> {
	private GAState gaState;
	
	public FitnessDoubleChromosomeSync(GAState gaState)
	{
		super(true); // bigger is better!
		this.gaState = gaState;
	}
	
	@Override
	public void evaluate(Individual<DoubleChromosome> arg0) {
		while( gaState.getState() != 0 )
		{
			try {
				Thread.sleep(125);
			} catch (InterruptedException e) {}
		}
		gaState.setParams( new Parameters(arg0.getChromosome().getValues()) );
		
		while( gaState.getState() != 3 )
		{
			try {
				Thread.sleep(125);
			} catch (InterruptedException e) {}
		}
		arg0.setScore(gaState.getScore());	
	}
}
